package se.peterbjorkman.android.trafikkamera;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;

public class CameraMapOverlay extends ItemizedOverlay<CameraOverlayItem> {

    private ArrayList<CameraOverlayItem> mOverlayItems = new ArrayList<CameraOverlayItem>();
    
	public CameraMapOverlay(Drawable defaultMarker) {
		super(boundCenter(defaultMarker));
	}
	
    public void clearOverlayItems(){
    	mOverlayItems.clear();
        populate();
    }

    public void addOverlayItem(CameraOverlayItem item) {
        mOverlayItems.add(item);
        
        //populate();
    }
    
    public void doPopulate() {
        populate();
    }
    
    @Override
    protected CameraOverlayItem createItem(int i) {
        return mOverlayItems.get(i);
    }

    @Override
    public int size() {
        return mOverlayItems.size();
    }
    
    public interface OnTapListener{
        public void onTap(CameraOverlayItem item);
    }
    
    private OnTapListener mTapListener = null;
    
    public void setOnTapListener(OnTapListener listener){
        mTapListener = listener;
    }
    
    @Override
    protected boolean onTap(int index) {
        if  (mTapListener != null){
            CameraOverlayItem item =  mOverlayItems.get(index);
            mTapListener.onTap(item);
            return true;
        }
        return false;
    }
    
    public static Drawable boundCenter(Drawable drawable){
        return ItemizedOverlay.boundCenter(drawable);
    }

}
